package com.example.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.HeadersExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : zhayh
 * @date : 2021-5-4 21:28
 * @description :
 */

@Configuration
public class RabbitMQHeaderConfig {
    @Bean
    Queue marketingQueue() {
        return new Queue("marketingQueue");
    }
    @Bean
    Queue financeQueue() {
        return new Queue("financeQueue");
    }
    @Bean
    Queue adminQueue() {
        return new Queue("adminQueue");
    }
    @Bean
    Queue allQueue() {
        return new Queue("allQueue");
    }

    @Bean
    HeadersExchange exchange() {
        return new HeadersExchange("header-exchange");
    }

    @Bean
    Binding marketingBinding(Queue marketingQueue, HeadersExchange exchange) {
        return BindingBuilder.bind(marketingQueue)
                .to(exchange)
                .where("department")
                .matches("marketing");
    }

    @Bean
    Binding financeBinding(Queue financeQueue, HeadersExchange exchange) {
        return BindingBuilder.bind(financeQueue)
                .to(exchange)
                .where("department")
                .matches("finance");
    }

    @Bean
    Binding adminBinding(Queue adminQueue, HeadersExchange exchange) {
        return BindingBuilder.bind(adminQueue)
                .to(exchange)
                .where("department")
                .matches("admin");
    }
}
